package com.managerProvider.controller;

import com.alibaba.fastjson.JSON;
import com.managerProvider.service.ProviderService;
import entity.Provider;
import entity.ResponseMessage;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * The type Provider controller.
 */
@RestController
@RequestMapping("/provider")
@CrossOrigin
public class ProviderController {
    @Autowired
    private ProviderService providerService;

    private Logger logger = Logger.getLogger(this.getClass());

    /**
     * Select all provider string.
     *
     * @param provider the provider
     * @return the string
     */
    @RequestMapping("/selectAllProvider")
    public String selectAllProvider(@RequestBody Provider provider) {
        ResponseMessage msg = providerService.selectAllProvider(provider);
        return JSON.toJSONString(msg);
    }

    /**
     * Insert provider string.
     *
     * @param provider the provider
     * @return the string
     */
    @RequestMapping("/insertProvider")
    public String insertProvider(@RequestBody Provider provider) {
        ResponseMessage msg = providerService.insertProvider(provider);
        return JSON.toJSONString(msg);
    }

    /**
     * Update provider string.
     *
     * @param provider the provider
     * @return the string
     */
    @RequestMapping("/updateProvider")
    public String updateProvider(@RequestBody Provider provider) {
        ResponseMessage msg = providerService.updateProvider(provider);
        return JSON.toJSONString(msg);
    }
}
